﻿using HungryCrowdLibrary;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HungryCrowd.category
{
    public partial class list : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            rptCategories.DataSource = API.CategoryManager.GetDtoList(x => x.IsActive == true);
            rptCategories.DataBind();
        }

        protected void btnViewTraders_Click(object sender, EventArgs e)
        {
            //var textBox = (TextBox)sender;
            //if (!string.IsNullOrWhiteSpace(textBox.Text))
            //    Response.Redirect(string.Format("http://localhost:49760/traders/list.aspx?id={0}", textBox.Text));
        }

        protected void rptCategories_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var category = (HungryCrowdLibrary.ModelDto.Category)e.Item.DataItem;
                var lnkViewTraders = (HyperLink)e.Item.FindControl("lnkViewTraders");
                var lnkURL = (HyperLink)e.Item.FindControl("lnkURL");

                lnkViewTraders.NavigateUrl = string.Format("{0}?id={1}", ConfigurationManager.AppSettings["tradersURL"], category.Id);
                
                lnkURL.Text = "View traders";
                lnkURL.NavigateUrl = string.Format("{0}?id={1}", ConfigurationManager.AppSettings["tradersURL"], category.Id);
                //GetRouteUrl("traders/list", new { id = category.Id }); 

            }
            
        } 
    }
}